
<%@ page import="handler.Au" %>
<%@ page import="handler.Refresh" %>
<%@ page import="java.sql.SQLException" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <style>
        body{
            font-family: Arial, sans-serif;
            background-color: #f0f0f0;
            padding: 20px;
            background-image: url("1.jpg");  /* 添加这行来引入背景图 */
            background-size: cover;  /* 使背景图充满整个容器 */
            background-repeat: no-repeat;  /* 不要重复背景图 */
        }
        #countdown {
            font-size: 20px;
            text-align: center;
            margin-top: 200px;
        }
        #re {
            font-size: 20px;
            text-align: center;
            position: absolute;
            top: 170px;
            left: 800px;

        }
    </style>
    <meta charset="UTF-8">
    <title>获取au</title>
    <link rel="stylesheet" href="https://cdn.example.com/styles/your-custom-style.css">
    <link rel="stylesheet" href="https://cdn.bootcss.com/sweetalert/1.1.3/sweetalert.min.css" />
    <script src="https://cdn.example.com/scripts/your-custom-script.js"></script>
    <script src="https://cdn.bootcss.com/sweetalert/1.1.3/sweetalert.min.js"></script>
</head>
<body align="center">
<div id="re">失效倒计时</div>
<div id="countdown">3:00</div>
<%
    Cookie[] cookies= request.getCookies();
    String username = null;
    if(cookies!=null){
        for (jakarta.servlet.http.Cookie cookie : cookies) {
            if(cookie.getName().equals("username")){
                username= cookie.getValue();
            }
        }
    }
    String au = null;
    String type = null;
    type = request.getParameter("type");
    if (type.equals("free")){
        type = "0";

    }else if (type.equals("39")){
        type = "1";
    }else if (type.equals("99")){
        type = "2";
    }
    au = Au.getAu(type);

%>
<div class="content-wrapper">
    请复制授权码：<h1 class="title-text" id="au" ><%= au%></h1>
    <!-- Other content goes here -->
</div>
<script>
    // ... [Your JavaScript code remains largely the same]
    document.body.oncopy = function() {
        swal("复制成功！", "", "success");
        var au= document.getElementById("au").innerHTML
        var xhr;
        if (window.XMLHttpRequest)
        {
            xhr=new XMLHttpRequest();
        }else{
            xhr=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xhr.open("post","makeAu",true);
        xhr.onreadystatechange=function() {
            if (xhr.readyState == xhr.DONE && xhr.status == 200) {
                document.getElementById("check").innerHTML = xhr.responseText;
            }
        }
        xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
        xhr.send("check=0&au="+au);
<%--        <%--%>
<%--            try {--%>
<%--                Refresh.refresh_state1(au);--%>
<%--                Refresh.refresh_u_a(au,username);--%>
<%--            } catch (SQLException e) {--%>
<%--                throw new RuntimeException(e);--%>
<%--            }--%>

<%--        %>--%>
    };
</script>
<script>
    var countdownElement = document.getElementById('countdown');
    var countdownInterval = setInterval(function() {
        var time = countdownElement.innerText.split(':');
        var minutes = parseInt(time[0]);
        var seconds = parseInt(time[1]);

        if (minutes === 0 && seconds === 0) {
            clearInterval(countdownInterval);
            countdownElement.innerText = "时间到！<meta http-equiv=refresh content=1;url=home.jsp>";
            return;
        }

        if (seconds === 0) {
            minutes--;
            seconds = 59;
        } else {
            seconds--;
        }

        if (minutes < 10) minutes = '0' + minutes;
        if (seconds < 10) seconds = '0' + seconds;

        countdownElement.innerText = minutes + ':' + seconds;
    }, 1000);
</script>
</body>
</html>